package com.kayt.cyberBar.cpublic.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cpublic.business.dao.IPublicTaskLevelDao;
import com.kayt.cyberBar.cpublic.business.entity.po.CPublicTaskLevel;

@Repository("publicTaskLevelDao")
public class PublicTaskLevelDaoImpl implements IPublicTaskLevelDao {
	@Autowired
	private EntityDao entityDao;
	@Override
	public CPublicTaskLevel findById(String taskLevelId) {
		if(StringUtils.isNotEmpty(taskLevelId)){
			Long id = null;
			try{
				id = Long.parseLong(taskLevelId);
			}catch (Exception e) {
				return null;
			}
			return entityDao.findById(id, CPublicTaskLevel.class);
		}else{
			return null;
		}
	}

	@Override
	public Integer delete(String taskLevelId) {
		if(StringUtils.isNotEmpty(taskLevelId)){
			Long id = null;
			try{
				id = Long.parseLong(taskLevelId);
				CPublicTaskLevel cPublicUserStatusCode = entityDao.findById(id, CPublicTaskLevel.class);
				if(cPublicUserStatusCode != null){
					entityDao.delete(cPublicUserStatusCode);
					return 0;
				}else{
					return -1;
				}
			}catch (Exception e) {
				return -1;
			}
		}else{
			return -1;
		}
	}

	@Override
	public void modify(CPublicTaskLevel entity) throws SQLException {
		entityDao.update(entity);
	}

	@Override
	public PageData<CPublicTaskLevel> findByPage(String hql, Object[] params, LinkedHashMap<String, String> orderMap) throws SQLException {
		PageData<CPublicTaskLevel> cPublicTaskLevelPageData = this.entityDao.getPagingData(CPublicTaskLevel.class, -1, -1, hql, params, orderMap);
		return cPublicTaskLevelPageData;
	}

	@Override
	public Long save(CPublicTaskLevel entity) throws SQLException {
		return this.entityDao.save(entity);
	}

	@Override
	public PageData<CPublicTaskLevel> getTaskLevelList(LinkedHashMap<String, String> orderMap) throws SQLException {
		PageData<CPublicTaskLevel> taskLevelPageData = this.entityDao.getPagingData(CPublicTaskLevel.class, -1, -1, null, null, orderMap);
		return taskLevelPageData;
	}
}
